//
//  ProblemFetchViewController.m
//  Utils
//
//  Created by enghou on 2018/4/17.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "ProblemFetchViewController.h"
#import "ManipulatorItemModel.h"
#import "ManipulatorViewController.h"
#import "SubEnterpriseViewController.h"
@interface ProblemFetchViewController ()

@end

@implementation ProblemFetchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

-(NSDictionary *)param{
    if ([self.manipulator_id length] == 0) {
        [self alertSome:@"请选择主办单位!"];
        return nil;
    }
    if ([self.subEnterprise_id length] == 0) {
        [self alertSome:@"请选择抄告单位!"];
        return nil;
    }
    if ([self.suggestionField.text length] == 0) {
        [self alertSome:@"请输入交办意见!"];
        return nil;
    }
    if (self.type == 0) {
        return @{@"issueStepId":self.stepId,@"logNew.dealDeadline":self.endTimeField.text,@"logNew.targeOrg.id":self.manipulator_id,@"tellOrgIds":self.subEnterprise_id,@"logNew.content":self.suggestionField.text};
    }else{
        return @{@"appealId":self.stepId,@"stepRecordId":self.stepId,@"shunt.hostOrgId":self.manipulator_id,@"shunt.chaoguOrgIds":self.subEnterprise_id,@"shunt.description":self.suggestionField.text,@"shunt.deadline":self.endTimeField.text};
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSString *)typeId{
    return @"70";
}

- (IBAction)showEndTimeAction:(id)sender {
    [self.dateField becomeFirstResponder];
}

-(void)cancelAction{
    [self.dateField resignFirstResponder];
}

-(void)sureAction{
    self.endTimeField.text = [[self.datePicker date]dateLineStrOnlyDay];
    [self.dateField resignFirstResponder];
}

-(void)pushToManipulator{
    ManipulatorViewController *vc = [[ManipulatorViewController alloc]init];
    vc.modelClsName = @"ManipulatorItemModel";
    vc.path = kFetchManipulator;
    vc.theDelete = self;
    vc.stepId = self.stepId;
    [(BaseViewController *)self.theDelete push:vc];
}

- (IBAction)showFilePicker:(id)sender {
    [super showFilePicker:sender];
}

-(void)pushToSubEnterprise{
    SubEnterpriseViewController *vc = [[SubEnterpriseViewController alloc]init];
    vc.modelClsName = @"ManipulatorItemModel";
    vc.path = kFetchSubEnterprise;
    vc.theDelete = self;
    vc.stepId = self.stepId;
    [(BaseViewController *)self.theDelete push:vc];
}

-(void)fetchArray:(NSArray *)array{
    NSMutableArray *ids = [NSMutableArray array];
    NSMutableArray *names = [NSMutableArray array];
    for (ManipulatorItemModel *model in array) {
        [ids addObject:model.code];
        [names addObject:model.name];
    }
    self.subEnterprise_id = [ids componentsJoinedByString:@","];
    self.subEnterpriseField.text = [names componentsJoinedByString:@","];
}

-(void)fetchModel:(id)model{
    ManipulatorItemModel *m = (ManipulatorItemModel *)model;
    self.manipulator_id = m.code;
    self.manipulatorField.text = m.name;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        [self showActions];
    }else if (indexPath.row == 2) {
        [self pushToManipulator];
    }else if (indexPath.row == 3){
        [self pushToSubEnterprise];
    }
}


@end
